package com.meng.android.adapter;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meng.android.util.R;

public class AdapterUtils {

	public static View createView(Context context, View convertView,
			ViewGroup parent) {
		return createView(context, convertView,
				R.layout.custome_list_item_with_image, parent);
	}

	public static View createView(Context context, View convertView,
			int resourceId, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			LayoutInflater mInflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(resourceId, parent, false);
			holder = new ViewHolder();

			holder.image = (ImageView) convertView
					.findViewById(R.id.image_icon);
			holder.title = (TextView) convertView
					.findViewById(R.id.list_item_title);
			holder.description = (TextView) convertView
					.findViewById(R.id.list_item_desc);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}

	public static View getView(View view, String title, String description,
			BitmapDrawable drawable) {
		ViewHolder holder = (ViewHolder) view.getTag();
		if (drawable != null) {
			holder.image.setImageDrawable(drawable);
		} else {
			// set default image here
		}
		holder.title.setText(title);
		holder.description.setText(description);
		
		if(view.isSelected()){
			
		}
		
		return view;
	}

	public static class ViewHolder {
		ImageView image;
		TextView title;
		TextView description;
	}

}